package com.zenith.middleware.feign.storage;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.PageResult;
import com.zenith.common.result.Result;
import com.zenith.middleware.po.dto.storage.*;
import com.zenith.middleware.po.vo.storage.*;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 存储服务Feign客户端
 */
@FeignClient(path = "/api/storage", name = "zenith-storage-service", contextId = "middleware-storage-client")
public interface StorageServiceFeignClient {
    // =========================== 分片上传相关接口 ===========================
    
    @SecurePostMapping("/initChunkUpload")
    public Result<ChunkInitVO> initChunkUpload(@Valid @RequestBody ChunkInitDTO chunkInitDTO);

    /**
     * 上传分片
     */
    @SecurePostMapping("/chunkUploadService")
    public Result<ChunkUploadVO> uploadChunk(@Valid @RequestBody ChunkUploadDTO chunkUploadDTO);

    /**
     * 完成分片上传
     */
    @SecurePostMapping("/completeChunkUpload")
    public Result<FileVO> completeChunkUpload(@Valid @RequestBody ChunkCompleteDTO chunkCompleteDTO);

    /**
     * 获取分片上传状态
     */
    @SecurePostMapping("/getChunkStatus/{uploadKey}")
    public Result<ChunkStatusVO> getChunkStatus(@PathVariable String uploadKey);

    // =========================== 网盘功能相关接口 ===========================
    
    @SecurePostMapping("/createFolder")
    public Result<FolderVO> createFolder(@Valid @RequestBody FolderDTO folderDTO);

    /**
     * 获取文件夹树
     */
    @SecurePostMapping("/getFolderTree")
    public Result<List<FolderVO>> getFolderTree(@RequestParam Long userId);

    /**
     * 获取文件夹中的文件列表
     */
    @SecurePostMapping("/getFolderFiles")
    public Result<PageResult<FolderFileVO>> getFolderFiles(FolderFileQueryDTO queryDTO);

    /**
     * 移动文件
     */
    @SecurePostMapping("/moveFile")
    public Result<Boolean> moveFile(@Valid @RequestBody MoveFileDTO moveFileDTO);

    /**
     * 重命名文件或文件夹
     */
    @SecurePostMapping("/rename")
    public Result<Boolean> rename(@Valid @RequestBody RenameDTO renameDTO);

    // =========================== 文件管理相关接口 ===========================
    
    @SecurePostMapping("/initUpload")
    public Result<UploadInitVO> initUpload(@Valid @RequestBody UploadInitDTO uploadInitDTO);

    /**
     * 上传文件
     */
    @SecurePostMapping("/uploadFile")
    public Result<FileVO> uploadFile(@RequestParam("file") MultipartFile file,
                                     @RequestParam("fileId") Long fileId);

    /**
     * 下载文件
     */
    @SecurePostMapping("/downloadFile/{fileId}")
    public void downloadFile(@PathVariable("fileId") Long fileId, HttpServletResponse response);

    /**
     * 删除文件
     */
    @SecurePostMapping("/deleteFile/{fileId}")
    public Result<Boolean> deleteFile(@PathVariable("fileId") Long fileId);

    /**
     * 获取文件详情
     */
    @SecurePostMapping("/getFileDetail/{fileId}")
    public Result<FileVO> getFileDetail(@PathVariable("fileId") Long fileId);

    /**
     * 分页查询文件列表
     */
    @SecurePostMapping("/listFiles")
    public Result<PageResult<FileVO>> listFiles(FileQueryDTO queryDTO);

    // =========================== 存储提供商相关接口 ===========================
    
    /**
     * 获取所有存储提供商列表
     */
    @SecurePostMapping("/listProviders")
    public Result<List<StorageProviderVO>> listProviders();

    /**
     * 添加存储提供商
     */
    @SecurePostMapping("/addProvider")
    public Result<Boolean> addProvider(@Valid @RequestBody ProviderDTO providerDTO);

    /**
     * 更新存储提供商
     */
    @SecurePostMapping("/updateProvider")
    public Result<Boolean> updateProvider(@Valid @RequestBody ProviderDTO providerDTO);

    /**
     * 删除存储提供商
     */
    @SecurePostMapping("/deleteProvider/{id}")
    public Result<Boolean> deleteProvider(@PathVariable("id") Long id);

    /**
     * 设置默认存储提供商
     */
    @SecurePostMapping("/setDefaultProvider/{id}")
    public Result<Boolean> setDefaultProvider(@PathVariable("id") Long id);

    /**
     * 获取默认存储提供商
     */
    @SecurePostMapping("/getDefaultProvider")
    public Result<StorageProviderVO> getDefaultProvider();
}